import { message } from 'antd';
import { getMenuList,getResList,addRoleRes,getRoleList,cancelAuth } from '../services'

export default {
    namespace: 'resModel',
    state: {
        resList: [],
        resTotal: 0,
    },
    
    effects: {
        *getMenuList({payload},{put,call,select}){
            return yield call(getMenuList, payload);
        },

        *getResList({payload},{put,call,select}){
            const res= yield call(getResList, payload);
            const { code, data,  message: errMsg } = res;
            if(code === 0) {
                const {total,dataList} = data;
                yield put({
                    type: 'updateModel',
                    payload: {
                        resList: dataList,
                        resTotal: total,
                    }
                })
            }else{
              message.error(errMsg);
            }
        },

        *getRoleList({payload},{put,call}){
            return yield call(getRoleList,payload);
        },

        *addRoleRes({payload},{put,call}){
            return yield call(addRoleRes,payload);
        },

        *cancelAuth({payload},{put,call}){
            return yield call(cancelAuth,payload);
        }

    },

    reducers:{
        updateModel: (state, { payload }) => ({
            ...state,
            ...payload,
        }),
    }
}